#include "stm32f10x.h"

int main(void)
{
	 // TIM1 1ch 1chn config
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
    // GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
   // 一路互补PWM输出 驱动
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
    // 配置TIM1
    TIM_TimeBaseInitTypeDef TIM1_TimeBaseInit;
    TIM1_TimeBaseInit.TIM_Prescaler         = 71; // 100KHz
    TIM1_TimeBaseInit.TIM_CounterMode       = TIM_CounterMode_Up;
    TIM1_TimeBaseInit.TIM_Period            = 999; // 1ms
    TIM1_TimeBaseInit.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit(TIM1, &TIM1_TimeBaseInit);
    
    TIM_ARRPreloadConfig(TIM1, ENABLE);
    // 使能TIM1
    TIM_Cmd(TIM1, ENABLE);
    // 配置输出比较
    TIM_OCInitTypeDef TIM1_OCInit;
    TIM1_OCInit.TIM_OCMode       = TIM_OCMode_PWM1;
    TIM1_OCInit.TIM_OCPolarity   = TIM_OCPolarity_High;
    TIM1_OCInit.TIM_OCNPolarity  = TIM_OCNPolarity_High;
    TIM1_OCInit.TIM_OutputState  = TIM_OutputState_Enable;
    TIM1_OCInit.TIM_OutputNState = TIM_OutputNState_Enable;
    TIM1_OCInit.TIM_Pulse        = 500;
    TIM_CCPreloadControl(TIM1, ENABLE);
    TIM_OC1Init(TIM1, &TIM1_OCInit);
    TIM_CtrlPWMOutputs(TIM1, ENABLE);
    TIM_SetCompare1(TIM1, 500);
    while (1) {
        // GPIO_SetBits(GPIOA, GPIO_Pin_8);
    }
    return 0;
}
